/**
 * Desc: NodeJS版的演示程序
 * Func: 
 */
import { inputStream, outputStream } from "./stdiowrap.mjs";
import coreLib from "./core.bundle.js";
import * as hdls from "../hdls/index.mjs";

/**
 * 定义电路仓库
 */
const ccRepo = (function () {
    const repo = new coreLib.tools.CircuitRepository();
    // 注册内建单元的HDL到缓存
    for (const hdl of coreLib.builtinUnits.hdls) {
        repo.builtinHDLCache.register(hdl.model, hdl);
    }
    // 注册内建单元的构造器到缓存
    for (const evalCtor of coreLib.builtinUnits.evalCtors) {
        repo.builtinEvalCtorCache.register(evalCtor.MODEL, evalCtor);
    }
    // 注册复合单元的HDL到缓存
    for (const key of Object.keys(hdls)) {
        const hdl = hdls[key];
        repo.compoundHDLCache.register(hdl.model, hdl);
    }
    return repo;
})();

// 构造APP
const app = new coreLib.shell.LogicCLIApp(ccRepo);
// 构造APP壳
const appShell = new coreLib.shell.LogicCLIShell({
    input: inputStream,
    output: outputStream,
    exit: () => {
        process.exit(0);
    }
});
// 输出内核版本号
appShell.writeLog("core version:", `"${coreLib.version}"`);
// 运行
appShell.run(app);
